from settings.common import *
import datetime
day_time = datetime.datetime.now().strftime('%Y-%m-%d')
DEPLOY_ZONE = ''

MIDDLEWARE = [
    'service.csrf_service.DisableCSRF',
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'service.permission.api_permission.ApiPermissionCheck',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',  # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'loonflow',  # Or path to database file if using sqlite3.
        'USER': 'loonflow',  # Not used with sqlite3.
        'PASSWORD': 'loonflow',  # Not used with sqlite3.
        'HOST': '10.0.0.51',  # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '3306',  # Set to empty string for default. Not used with sqlite3.
    }
}

REDIS_HOST = '10.0.0.51'
REDIS_PORT = 6379
REDIS_DB = 0
REDIS_PASSWORD = ''

if REDIS_PASSWORD:
    CELERY_BROKER_URL = 'redis://:{}@{}:{}/{}'.format(REDIS_PASSWORD, REDIS_HOST, REDIS_PORT, REDIS_DB)
else:
    CELERY_BROKER_URL = 'redis://{}:{}/{}'.format(REDIS_HOST, REDIS_PORT, REDIS_DB)

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_true': {
            '()': 'django.utils.log.RequireDebugTrue',
        },
    },
    'formatters': {
        'standard': {
            'format': '%(asctime)s %(pathname)s process-%(process)d thread-%(thread)d %(lineno)d [%(levelname)s]: %(message)s',
        },
    },
    'handlers': {
        'file_handler': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': os.path.join(os.path.dirname(BASE_DIR), "logs", "bybitflow_%s.log" % day_time),
            # 'filename': HOMEPATH + '/loonflow.log',
            'formatter': 'standard'
        },
        'console': {
            'level': 'DEBUG',
            'filters': ['require_debug_true'],
            'class': 'logging.StreamHandler',
            'formatter': 'standard'
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file_handler'],
            'propagate': True,
            'level': 'INFO',
        },
        'django.db.backends': {
            'handlers': ['console'],
            'propagate': True,
            'level': 'INFO',
        }
    }
}

UEDITER_SETTING = {
    "fileMaxSize": 10240000,
    "scrawlPathFormat": "",
    "imageUrlPrefix": "",
    "catcherFieldName": "source",
    "snapscreenPathFormat": "",
    "imageFieldName": "upfile",
    "imagePathFormat": "",
    "filePathFormat": "",
    "scrawlMaxSize": 10485760,
    "catcherPathFormat": "",
    "scrawlUrlPrefix": "",
    "videoAllowFiles": [".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", ".ogg", ".ogv", ".mov", ".wmv",
                        ".mp4", ".webm", ".mp3", ".wav", ".mid"],
    "imageManagerAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"],
    "fileManagerListPath": "",
    "imageManagerUrlPrefix": "",
    "scrawlActionName": "uploadscrawl",
    "imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"],
    "imageManagerListSize": 30,
    "imageManagerActionName": "listimage",
    "videoUrlPrefix": "",
    "fileManagerActionName": "listfile",
    "fileManagerAllowFiles": [".sql", ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tif", ".psd.flv", ".swf", ".mkv",
                              ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm",
                              ".mp3", ".wav", ".mid", ".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
                              ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml", ".exe",
                              ".com", ".dll", ".msi"],
    "snapscreenUrlPrefix": "",
    "snapscreenActionName": "uploadimage",
    "catcherLocalDomain": ["127.0.0.1", "localhost", "img.baidu.com"],
    "imageActionName": "uploadimage",
    "fileUrlPrefix": "",
    "catcherActionName": "catchimage",
    "imageManagerListPath": "",
    "scrawlFieldName": "upfile",
    "fileManagerUrlPrefix": "",
    "videoActionName": "uploadvideo",
    "fileAllowFiles": [".sql", ".jpg", ".jpeg", ".bmp", ".gif", ".png", ".xls", ".xlsx", ".rar", ".doc", ".docx",
                       ".zip", ".pdf", ".txt", ".swf", ".wmv"],
    "videoPathFormat": "",
    "fileFieldName": "upfile",
    "catcherUrlPrefix": "",
    "catcherMaxSize": 1048576,
    "fileManagerListSize": 30,
    "catcherAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"],
    "imageMaxSize": 10485760,
    "videoMaxSize": 10240000,
    "fileActionName": "uploadfile",
    "videoFieldName": "upfile"
}

## MY LDAP配置
MY_LDAP_SERVER_URI = 'ldap://172.18.4.191:389'
MY_LDAP_BIND_DN = 'ldapuser'
MY_LDAP_BIND_PASSWORD = 'L9Fx3rgHttp7dfXA'
MY_LDAP_SEARCH_BASE = 'ou=Bybit,ou=bybit-testdev,dc=bybit-testdev,dc=com'

## JWT配置

JWT_AUTH = {
    # user => payload
    'JWT_PAYLOAD_HANDLER':
        'rest_framework_jwt.utils.jwt_payload_handler',
    # payload => token
    'JWT_ENCODE_HANDLER':
        'rest_framework_jwt.utils.jwt_encode_handler',
    # token => payload
    'JWT_DECODE_HANDLER':
        'rest_framework_jwt.utils.jwt_decode_handler',
    # token过期时间
    'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),
    # token刷新的过期时间
    'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=1),
}
